package com.dudao.modules.course.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.dudao.common.constant.Constant;
import com.dudao.common.page.PageData;
import com.dudao.common.service.impl.CrudServiceImpl;
import com.dudao.common.utils.ConvertUtils;
import com.dudao.modules.course.dao.CourseInitialDao;
import com.dudao.modules.course.dto.CourseInitialDTO;
import com.dudao.modules.course.entity.CourseInitialEntity;
import com.dudao.modules.course.service.CourseInitialService;
import com.dudao.modules.security.user.SecurityUser;
import com.dudao.modules.security.user.UserDetail;
import com.dudao.modules.sys.dto.SysRoleDTO;
import com.dudao.modules.sys.entity.SysRoleEntity;
import com.dudao.modules.sys.enums.SuperAdminEnum;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 *
 *
 * @author Lii juliip@163.com
 * @since 1.0.0 2022-11-05
 */
@Service
public class CourseInitialServiceImpl extends CrudServiceImpl<CourseInitialDao, CourseInitialEntity, CourseInitialDTO> implements CourseInitialService {


    @Override
    public PageData<CourseInitialDTO> page(Map<String, Object> params) {
        IPage<CourseInitialEntity> page = baseDao.selectPage(
                getPage(params, Constant.ID, true),
                getWrapper(params)
        );

        return getPageData(page, CourseInitialDTO.class);
    }


    @Override
    public List<CourseInitialDTO> list(Map<String, Object> params) {
        List<CourseInitialEntity> entityList = baseDao.selectList(getWrapper(params));

        return ConvertUtils.sourceToTarget(entityList, CourseInitialDTO.class);
    }

    @Override
    public QueryWrapper<CourseInitialEntity> getWrapper(Map<String, Object> params){
        String courseName = (String)params.get("courseName");
        String courseTeacher = (String) params.get("courseTeacher");
        QueryWrapper<CourseInitialEntity> wrapper = new QueryWrapper<>();
        wrapper.like(StringUtils.isNotBlank(courseName), "course_name", courseName)
                .like(StringUtils.isNotBlank(courseTeacher), "course_teacher", courseTeacher);

        return wrapper;
    }


}
